//
//  EmoticonsCell.m
//  微博
//
//  Created by zxy on 2019/1/10.
//  Copyright © 2019 zxy. All rights reserved.
//

#import "EmoticonsCell.h"
@interface EmoticonsCell()
@property(nonatomic,strong)UIButton *emoticonBtn;
@end
@implementation EmoticonsCell


- (instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectInset(self.contentView.bounds, 4, 4);
        btn.backgroundColor = [UIColor whiteColor];
        btn.userInteractionEnabled = NO;
        [self.contentView addSubview:btn];
        self.emoticonBtn = btn;
    }
    return self;
}

-(void)setModel:(EmoticonsImageModel *)model{
    _model = model;
    if(model.chs != nil){//判断是否是图片表情
        NSString *emPath = [[self EmoticonsPath:self.emoticonsId] stringByAppendingPathComponent:model.png];
        [self.emoticonBtn setImage:[UIImage imageWithContentsOfFile:emPath] forState:UIControlStateNormal];
    }else{//emoji表情(就是字符串)
        [self.emoticonBtn setImage:nil forState:UIControlStateNormal];
        if(model.code !=nil){
//            NSString *emojiStr = [NSString emojiWithStringCode:model.code];
             [self.emoticonBtn setTitle:model.emojiStr forState:UIControlStateNormal];
        }else{//在这里必须判断，不然来回滚动，空白按钮会复用图片表情
            [self.emoticonBtn setTitle:@"" forState:UIControlStateNormal];
        }
    }
    //判断是否显示删除按钮
    if(model.isShowRemoveBtn){//显示删除按钮
        [self.emoticonBtn setImage:[UIImage imageNamed:@"compose_emotion_delete"] forState:UIControlStateNormal];
        [self.emoticonBtn setImage:[UIImage imageNamed:@"compose_emotion_delete_highlighted"] forState:UIControlStateHighlighted];
    }
}

-(NSString *)EmoticonsPath:(NSString *)emoticonsDirectoryName{
    return [[self EmoticonsBundlePath] stringByAppendingPathComponent:emoticonsDirectoryName];
}

#pragma mark - 表情bundel路径
-(NSString *)EmoticonsBundlePath{
    return [[NSBundle mainBundle] pathForResource:@"Emoticons.bundle" ofType:nil];
}


@end
